package com.ayg.service;

import com.ayg.mapper.TrainingPlanMapper;
import com.ayg.pojo.TrainingPlans;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class TrainingPlanServiceImpl implements TrainingPlanService{

    @Autowired
    private TrainingPlanMapper trainingPlanMapper;

    /**
     * 添加培养计划
     * @param trainingPlans
     */
    @Override
    public void AddTrainingPlan(TrainingPlans trainingPlans) {
        trainingPlans.setParentId(0);
        trainingPlans.setStatus(true);
        trainingPlanMapper.insert(trainingPlans);
    }

    /**
     * 查询培养计划
     * @return
     */
    @Override
    public List<TrainingPlans> getTrainingPlan() {
        QueryWrapper<TrainingPlans> TrainingPlanQueryWrapper = new QueryWrapper<>();
        TrainingPlanQueryWrapper.eq("parent_id",0);
        List<TrainingPlans> trainingPlansList = trainingPlanMapper.selectList(TrainingPlanQueryWrapper);

        return trainingPlansList;
    }

    /**
     * 查询学习计划
     * @param trainingPlan
     * @return
     */
    @Override
    public List<TrainingPlans> AddOneTrainingPlan(String trainingPlan) {
        QueryWrapper<TrainingPlans> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("training_plan_name",trainingPlan).eq("parent_id",0);
        List<TrainingPlans> planList = trainingPlanMapper.selectList(queryWrapper);

        return planList;
    }

    /**
     * 添加学习培养计划
     * @param trainingPlans
     */
    @Override
    public void LearningCultivate(TrainingPlans trainingPlans) {
        trainingPlans.setTrainingPlanName(trainingPlans.getTrainingPlanName());
        trainingPlans.setProjectName(trainingPlans.getProjectName());
        trainingPlans.setParentId(1);
        trainingPlans.setStatus(true);
        trainingPlans.setDate(new SimpleDateFormat("yyyy年MM月dd日").format(new Date()));
        trainingPlanMapper.insert(trainingPlans);


    }

    /**
     * 添加兴趣培养计划
     * @param trainingPlans
     */
    @Override
    public void interestCultivation(TrainingPlans trainingPlans) {
        trainingPlans.setTrainingPlanName(trainingPlans.getTrainingPlanName());
        trainingPlans.setProjectName(trainingPlans.getProjectName());
        trainingPlans.setParentId(2);
        trainingPlans.setStatus(true);
        trainingPlans.setDate(new SimpleDateFormat("yyyy年MM月dd日").format(new Date()));
        trainingPlanMapper.insert(trainingPlans);
    }

    /**
     * 添加生活技能掌握
     * @param trainingPlans
     */
    @Override
    public void SkillCultivation(TrainingPlans trainingPlans) {
        trainingPlans.setTrainingPlanName(trainingPlans.getTrainingPlanName());
        trainingPlans.setProjectName(trainingPlans.getProjectName());
        trainingPlans.setParentId(3);
        trainingPlans.setStatus(true);
        trainingPlans.setDate(new SimpleDateFormat("yyyy年MM月dd日").format(new Date()));
        trainingPlanMapper.insert(trainingPlans);
    }

    /**
     * 添加获得荣誉
     * @param trainingPlans
     */
    @Override
    public void HonorCultivation(TrainingPlans trainingPlans) {
        trainingPlans.setTrainingPlanName(trainingPlans.getTrainingPlanName());
        trainingPlans.setProjectName(trainingPlans.getProjectName());
        trainingPlans.setParentId(4);
        trainingPlans.setStatus(true);
        trainingPlans.setDate(new SimpleDateFormat("yyyy年MM月dd日").format(new Date()));
        trainingPlanMapper.insert(trainingPlans);
    }

    /**
     * 查询第二级parent_id=1
     * @param trainingPlans
     * @return
     */
    @Override
    public List<TrainingPlans> AddSecondTrainingPlan(TrainingPlans trainingPlans) {
        QueryWrapper<TrainingPlans> SecondQueryWrapper = new QueryWrapper<>();
        SecondQueryWrapper.eq("training_plan_name",trainingPlans.getTrainingPlanName()).eq("parent_id",trainingPlans.getParentId());
        List<TrainingPlans> SecondList = trainingPlanMapper.selectList(SecondQueryWrapper);
        return SecondList;
    }

    /**
     * 查询第二级菜单信息
     * @param trainingPlans
     * @return
     */
    @Override
    public List<TrainingPlans> AddInnerDrawerTrainingPlan(TrainingPlans trainingPlans) {
        QueryWrapper<TrainingPlans> InnerDrawerQueryWrapper = new QueryWrapper<>();
        InnerDrawerQueryWrapper.eq("parent_id",trainingPlans.getParentId())
                .eq("project_name",trainingPlans.getProjectName());
        List<TrainingPlans> InnerDrawerList = trainingPlanMapper.selectList(InnerDrawerQueryWrapper);
        return InnerDrawerList;
    }

    @Override
    public List<TrainingPlans> getBrowseTrainingList() {
        QueryWrapper<TrainingPlans> browseQueryWrapper = new QueryWrapper<>();
        browseQueryWrapper.select("parent_id","honor_url").eq("parent_id",4);
        List<TrainingPlans> trainingPlansList = trainingPlanMapper.selectList(browseQueryWrapper);
        return trainingPlansList;
    }


}
